package cn.okcmd.aboutRedis;

import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

/**
 * create by caoqg on 2021/10/28
 * 功能说明:
 */
@Slf4j
public class MyClusterTest {

    public static void main(String[] args) {
        Set<HostAndPort> jedisSockets = new HashSet<>();
        jedisSockets.add(new HostAndPort("localhost", 9001));
        jedisSockets.add(new HostAndPort("localhost", 9002));
        jedisSockets.add(new HostAndPort("localhost", 9003));
        jedisSockets.add(new HostAndPort("localhost", 9004));
        jedisSockets.add(new HostAndPort("localhost", 9005));
        jedisSockets.add(new HostAndPort("localhost", 9006));
        JedisCluster jedisCluster = new JedisCluster(jedisSockets);
        for (int i = 0; i < 10; i++) {
            jedisCluster.set("key" + i, "value" + i);
        }
        for (int i = 0; i < 10; i++) {
            String key = "key" + i;
            String value = jedisCluster.get(key);
            log.info("the key:{},the value:{}",key,value);
        }
    }
}
